package fy.mdm.operator;

import com.seeyon.v3x.services.flow.bean.FlowExport;
import com.seeyon.v3x.services.form.bean.ValueExport;
import fy.form.listen.operate.AForm_Save_Operator;
import fy.form.listen.operate.IFormOperator;
import fy.mdm.bean.PartEditCustomerBean;
import fy.mdm.bean.PartNewCustomerBean;
import fy.mdm.dao.FiexdAssetReviewDao;
import fy.mdm.dao.PartEditCustomerDao;
import fy.mdm.dao.PartNewCustomerDao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

public class PartEditCustomerOperator extends AForm_Save_Operator implements
        IFormOperator {
    private static Log log = LogFactory.getLog(FiexdAssetReviewDao.class);
    private PartEditCustomerBean bean = new PartEditCustomerBean();
    @Override
    public String getFormName() {
        return "配件客户修改申请表";
    }
    @Override
    protected void parseOtherField_FirstStep(FlowExport flowExport) {
        bean.setSummaryId(super.formBean.getSummaryId());
        bean.setBillname(flowExport.getFlowTitle());
        bean.setApplier(flowExport.getFlowCreatePerson().getId());
        bean.setTs(flowExport.getFlowCreateTime());
    }
    @Override
    protected void parseValueExport(ValueExport ve) {
        String fieldName = ve.getDisplayName();
        if ("客户编码".equals(fieldName)) {
            bean.setCUSTOMER_CODE(ve.getValue());
        }else if("客户类型".equals(fieldName)){
            bean.setCUSTOMER_STYLE(ve.getValue());
        }else if("客户名称-变更后".equals(fieldName)){
            bean.setCUSTOMER_NAME(ve.getValue());
        }else if("客户国别-变更后".equals(fieldName)){
            bean.setCOUNTRY(ve.getValue());
        }else if("客户国别-变更后".equals(fieldName)){
            bean.setCOUNTRY(ve.getValue());
        }else if("客户注册地址-变更后".equals(fieldName)){
            bean.setADDRESS(ve.getValue());
        }else if("信用天数-变更后".equals(fieldName)){
            bean.setDAYS(ve.getValue());
        }else if("客户状态-变更后".equals(fieldName)){
            bean.setSTATUS(ve.getValue());
        }
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        bean.setAPPROVER_TIME(format);
    }

    @Override
    protected boolean save() {
                try {
            System.out.println("save PartNewCustomerOperator");
            PartEditCustomerDao partEditCustomerDao = new PartEditCustomerDao();
            partEditCustomerDao.setPartEditCustomerBean(bean);
            return partEditCustomerDao.StateReturn();

        } catch (Exception e) {
            e.printStackTrace();
        }finally {

        }
        return success;
    }
}
